package com.lxmes.procontrol.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.procontrol.domain.NcProContrReport;
import com.lxmes.procontrol.service.INcProContrReportService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 生产控制报Controller
 *
 * @author ruoyi
 * @date 2023-03-06
 */
@RestController
@RequestMapping("/procontrol/proContrReport")
public class NcProContrReportController extends BaseController
{
    @Autowired
    private INcProContrReportService ncProContrReportService;

    /**
     * 查询生产控制报列表
     */
    @PreAuthorize("@ss.hasPermi('procontrol:proContrReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcProContrReport ncProContrReport)
    {
        startPage();
        List<NcProContrReport> list = ncProContrReportService.selectNcProContrReportList(ncProContrReport);
        return getDataTable(list);
    }

    /**
     * 导出生产控制报列表
     */
    @PreAuthorize("@ss.hasPermi('procontrol:proContrReport:export')")
    @Log(title = "生产控制报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcProContrReport ncProContrReport)
    {
        List<NcProContrReport> list = ncProContrReportService.selectNcProContrReportList(ncProContrReport);
        ExcelUtil<NcProContrReport> util = new ExcelUtil<NcProContrReport>(NcProContrReport.class);
        util.exportExcel(response, list, "生产控制报数据");
    }

    /**
     * 获取生产控制报详细信息
     */
    @PreAuthorize("@ss.hasPermi('procontrol:proContrReport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncProContrReportService.selectNcProContrReportById(id));
    }

    /**
     * 新增生产控制报
     */
    @PreAuthorize("@ss.hasPermi('procontrol:proContrReport:add')")
    @Log(title = "生产控制报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcProContrReport ncProContrReport)
    {
        return toAjax(ncProContrReportService.insertNcProContrReport(ncProContrReport));
    }

    /**
     * 修改生产控制报
     */
    @PreAuthorize("@ss.hasPermi('procontrol:proContrReport:edit')")
    @Log(title = "生产控制报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcProContrReport ncProContrReport)
    {
        return toAjax(ncProContrReportService.updateNcProContrReport(ncProContrReport));
    }

    /**
     * 删除生产控制报
     */
    @PreAuthorize("@ss.hasPermi('procontrol:proContrReport:remove')")
    @Log(title = "生产控制报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncProContrReportService.deleteNcProContrReportByIds(ids));
    }

    /**
     * 导入生产控制报
     */
    @Log(title = "生产控制报", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcProContrReport> util = new ExcelUtil<>(NcProContrReport.class);
        List<NcProContrReport> ncProContrReportList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncProContrReportService.imporIteminfo(ncProContrReportList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcProContrReport> util = new ExcelUtil<>(NcProContrReport.class);
        util.importTemplateExcel(response,"生产控制报");
    }
}
